#include "stdafx.h"
#include <stdio.h>

void main(){
	
	FILE *ifp, *ofp;//input/output file pointers
	int c, c1, c2;//variables used to store and compare input characters, c2 is used only to check for a </p> tag
	int n = 0;
	int count = 0;//counter for total characters in file
	int putCount = 0;//counter for number of outputted characters
	int discardTag = 0;	//counter to store number of discarded tags
	float charDiff = 0;//variable to store file size difference
	int br = 0; //counter for <br />
	int p = 0;//counter for <p>
	ifp = fopen("prog1in1.txt", "r");
	if(ifp == NULL){	
	
	}
	ofp = fopen("prog1in1out.txt", "w");
	
	do{
		c = getc(ifp);
		count ++;
		//compares the current character to '<' if its found starts a while loop
		if(c == '<'){
			//loops until it reaches the end of the tag
			while( c != '>'){
				count ++;
				c = getc(ifp);
				//c1 = c;
				//c2 = c1;
				
				

				
				/*compares the first two characters to determine if it is a <br /> tag 
				if true outputs a null line and counts the number of <br /> tags*/
				if(c == 'b' ){
					c = getc(ifp);
					count ++;
					if( /*c == 'b' &&*/ c == 'r'){
					br ++;
					c = '\n';
					putc( c , ofp);
					count += 1;
				}
					
				}//end br if
				
				
				/*else if if the tag is <p> outputs two null lines 
				and counts the number of <p> tags*/
				else if ( c == 'p' ){
					p ++;
					c = '\n';
					putc( c ,ofp);
					putc( c, ofp);
					count +=2;
					
				}//end p if

				//counts the number of tags that are not <br />				
				else{ //if ( c2 != 'b' && c1 != 'r' || c1 != 'p'){
					discardTag ++;
				}// end discard tag
			}//end while
			
		}
		
			/*checks if the current character is not '>' 
			if true outputs the current character*/
			if( c != '>'){
				putc( c , ofp);
				putCount++;
			}
			else if( c == EOF){
				
				
			}
			
				
			
						
	}while(c != EOF);
	fclose(ifp);
	/*charDiff = (count / putCount) * 100;
	printf("%c%i%s",'\n', discardTag, "discarded tags");
	printf("%c%i%s",'\n', br, "total <br />");
	printf("%c%i%s",'\n', p, "total <p>");
	printf("%c%i%s",'\n', count, "total characters");
	printf("%c%i%s",'\n', putCount, "total put characters");
	scanf("%i", n);*/
	
	

	
}//end main
